<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="用户名" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入用户名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input
          v-model="queryParams.password"
          placeholder="请输入密码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="昵称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入昵称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="userPhone">
        <el-input
          v-model="queryParams.userPhone"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信标识" prop="wxOpenid">
        <el-input
          v-model="queryParams.wxOpenid"
          placeholder="请输入微信标识"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付宝标识" prop="aliOpenid">
        <el-input
          v-model="queryParams.aliOpenid"
          placeholder="请输入支付宝标识"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户详细地址" prop="userPath">
        <el-input
          v-model="queryParams.userPath"
          placeholder="请输入用户详细地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会员等级" prop="memberRank">
        <el-input
          v-model="queryParams.memberRank"
          placeholder="请输入会员等级"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="真实姓名" prop="realName">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入真实姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="identityNumber">
        <el-input
          v-model="queryParams.identityNumber"
          placeholder="请输入身份证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="随机字符串" prop="randomStr">
        <el-input
          v-model="queryParams.randomStr"
          placeholder="请输入随机字符串"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否是技师" prop="isTechnician">
        <el-input
          v-model="queryParams.isTechnician"
          placeholder="请输入是否是技师"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="技师擅长领域" prop="technicianSpecialtyId">
        <el-input
          v-model="queryParams.technicianSpecialtyId"
          placeholder="请输入技师擅长领域"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星级评分" prop="technicianStarLevel">
        <el-input
          v-model="queryParams.technicianStarLevel"
          placeholder="请输入星级评分"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会员到期时间" prop="memberTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.memberTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择会员到期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="注册时间" prop="regTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.regTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择注册时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="用户性别" prop="personageSex">
        <el-select v-model="queryParams.personageSex" placeholder="请选择用户性别" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="用户出生日期" prop="personageBirthday">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.personageBirthday"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择用户出生日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="星级评定标识-外键" prop="starId">
        <el-input
          v-model="queryParams.starId"
          placeholder="请输入星级评定标识-外键"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职称(技师)" prop="jobTitle">
        <el-input
          v-model="queryParams.jobTitle"
          placeholder="请输入职称(技师)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司名" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入公司名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="休息时间" prop="restTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.restTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择休息时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:personage:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:personage:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:personage:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:personage:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="personageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户标识" align="center" prop="uid" />
      <el-table-column label="用户名" align="center" prop="username" />
      <el-table-column label="密码" align="center" prop="password" />
      <el-table-column label="昵称" align="center" prop="name" />
      <el-table-column label="用户头像" align="center" prop="personageImage" />
      <el-table-column label="手机号" align="center" prop="userPhone" />
      <el-table-column label="微信标识" align="center" prop="wxOpenid" />
      <el-table-column label="支付宝标识" align="center" prop="aliOpenid" />
      <el-table-column label="用户详细地址" align="center" prop="userPath" />
      <el-table-column label="会员等级" align="center" prop="memberRank" />
      <el-table-column label="真实姓名" align="center" prop="realName" />
      <el-table-column label="身份证号" align="center" prop="identityNumber" />
      <el-table-column label="随机字符串" align="center" prop="randomStr" />
      <el-table-column label="身份证正面" align="center" prop="identityJustImg" />
      <el-table-column label="身份证反面" align="center" prop="identityAgainstImg" />
      <el-table-column label="是否是技师" align="center" prop="isTechnician" />
      <el-table-column label="技师擅长领域" align="center" prop="technicianSpecialtyId" />
      <el-table-column label="星级评分" align="center" prop="technicianStarLevel" />
      <el-table-column label="会员到期时间" align="center" prop="memberTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.memberTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="注册时间" align="center" prop="regTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.regTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户性别" align="center" prop="personageSex" />
      <el-table-column label="用户出生日期" align="center" prop="personageBirthday" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.personageBirthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="星级评定标识-外键" align="center" prop="starId" />
      <el-table-column label="职称(技师)" align="center" prop="jobTitle" />
      <el-table-column label="公司名" align="center" prop="companyName" />
      <el-table-column label="休息时间" align="center" prop="restTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.restTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:personage:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:personage:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户名" prop="username">
          <el-input v-model="form.username" placeholder="请输入用户名" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="form.password" placeholder="请输入密码" />
        </el-form-item>
        <el-form-item label="昵称" prop="name">
          <el-input v-model="form.name" placeholder="请输入昵称" />
        </el-form-item>
        <el-form-item label="用户头像" prop="personageImage">
          <el-input v-model="form.personageImage" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="手机号" prop="userPhone">
          <el-input v-model="form.userPhone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="微信标识" prop="wxOpenid">
          <el-input v-model="form.wxOpenid" placeholder="请输入微信标识" />
        </el-form-item>
        <el-form-item label="支付宝标识" prop="aliOpenid">
          <el-input v-model="form.aliOpenid" placeholder="请输入支付宝标识" />
        </el-form-item>
        <el-form-item label="用户详细地址" prop="userPath">
          <el-input v-model="form.userPath" placeholder="请输入用户详细地址" />
        </el-form-item>
        <el-form-item label="会员等级" prop="memberRank">
          <el-input v-model="form.memberRank" placeholder="请输入会员等级" />
        </el-form-item>
        <el-form-item label="真实姓名" prop="realName">
          <el-input v-model="form.realName" placeholder="请输入真实姓名" />
        </el-form-item>
        <el-form-item label="身份证号" prop="identityNumber">
          <el-input v-model="form.identityNumber" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="随机字符串" prop="randomStr">
          <el-input v-model="form.randomStr" placeholder="请输入随机字符串" />
        </el-form-item>
        <el-form-item label="身份证正面" prop="identityJustImg">
          <el-input v-model="form.identityJustImg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="身份证反面" prop="identityAgainstImg">
          <el-input v-model="form.identityAgainstImg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否是技师" prop="isTechnician">
          <el-input v-model="form.isTechnician" placeholder="请输入是否是技师" />
        </el-form-item>
        <el-form-item label="技师擅长领域" prop="technicianSpecialtyId">
          <el-input v-model="form.technicianSpecialtyId" placeholder="请输入技师擅长领域" />
        </el-form-item>
        <el-form-item label="星级评分" prop="technicianStarLevel">
          <el-input v-model="form.technicianStarLevel" placeholder="请输入星级评分" />
        </el-form-item>
        <el-form-item label="会员到期时间" prop="memberTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.memberTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择会员到期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="注册时间" prop="regTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.regTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择注册时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="用户性别">
          <el-select v-model="form.personageSex" placeholder="请选择用户性别">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="用户出生日期" prop="personageBirthday">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.personageBirthday"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择用户出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="星级评定标识-外键" prop="starId">
          <el-input v-model="form.starId" placeholder="请输入星级评定标识-外键" />
        </el-form-item>
        <el-form-item label="职称(技师)" prop="jobTitle">
          <el-input v-model="form.jobTitle" placeholder="请输入职称(技师)" />
        </el-form-item>
        <el-form-item label="公司名" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入公司名" />
        </el-form-item>
        <el-form-item label="休息时间" prop="restTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.restTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择休息时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPersonage, getPersonage, delPersonage, addPersonage, updatePersonage, exportPersonage } from "@/api/system/personage";

export default {
  name: "Personage",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 用户表格数据
      personageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        username: undefined,
        password: undefined,
        name: undefined,
        personageImage: undefined,
        userPhone: undefined,
        wxOpenid: undefined,
        aliOpenid: undefined,
        userPath: undefined,
        memberRank: undefined,
        realName: undefined,
        identityNumber: undefined,
        randomStr: undefined,
        identityJustImg: undefined,
        identityAgainstImg: undefined,
        isTechnician: undefined,
        technicianSpecialtyId: undefined,
        technicianStarLevel: undefined,
        memberTime: undefined,
        regTime: undefined,
        personageSex: undefined,
        personageBirthday: undefined,
        starId: undefined,
        jobTitle: undefined,
        companyName: undefined,
        restTime: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listPersonage(this.queryParams).then(response => {
        this.personageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        uid: undefined,
        username: undefined,
        password: undefined,
        name: undefined,
        personageImage: undefined,
        userPhone: undefined,
        wxOpenid: undefined,
        aliOpenid: undefined,
        userPath: undefined,
        memberRank: undefined,
        realName: undefined,
        identityNumber: undefined,
        randomStr: undefined,
        identityJustImg: undefined,
        identityAgainstImg: undefined,
        isTechnician: undefined,
        technicianSpecialtyId: undefined,
        technicianStarLevel: undefined,
        memberTime: undefined,
        regTime: undefined,
        personageSex: undefined,
        personageBirthday: undefined,
        starId: undefined,
        jobTitle: undefined,
        companyName: undefined,
        restTime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.uid)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const uid = row.uid || this.ids
      getPersonage(uid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.uid != undefined) {
            updatePersonage(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addPersonage(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const uids = row.uid || this.ids;
      this.$confirm('是否确认删除用户编号为"' + uids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delPersonage(uids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有用户数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportPersonage(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>